//
//  BGFuJiaController.m
//  bigMall
//
//  Created by ios on 16/8/4.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGFuJiaController.h"
#import "BGHuoPinZhengShuController.h"
#import "BGFuJiaCell.h"
#import "BGFuJiaoneCell.h"
#import "BGOneCell.h"
#import "BGTwoCell.h"
#import "BGThreeCell.h"
#import "BGFiveCell.h"
#import "BGFourCell.h"
#import "BGDateResult.h"
#import "BGCategoryAttrResultModel.h"
#import "BGCategoryAttrModel.h"
#import "BGFaBuViewController.h"
#import "BGId_ValueModel.h"
#import "BGAddGoodsStepTwoModel.h"
#import "BGReadAddGoodsStepTWoModel.h"
#import "MJExtension.h"
#import "BGFuJiaThreeModel.h"
#import "MBProgressHUD.h"
#import "MBProgressHUD+MJ.h"
#import "BGReadStepTwoModel.h"
#import "BGDanXuanCell.h"
#import "BGDuoXuanCell.h"
#import "BGWenBenCell.h"
#import "BGInventoryCell.h"

@interface BGFuJiaController () <UITableViewDelegate,UITableViewDataSource,duoXuanDelegate,twoDelegate,danxuanDelegate,fourDelegate,fiveDelegate,WenBenDelegate> {
    
    UITableView *_tableView;
    NSInteger Index;
    NSArray *res;
    NSMutableArray *oneArr;
    NSMutableArray *twoArr;
    NSMutableArray *threeArr;
    NSMutableArray *fourArr;//文本的
    NSMutableArray *fiveArr;
    UIBarButtonItem *back;
    
    NSMutableArray *oneModelArr;
    NSMutableArray *twoModelArr;
    NSMutableArray *threeModelArr;
    NSMutableArray *fourModelArr;
    NSMutableArray *fiveModelArr;
    
    NSMutableArray *textData;
    NSString *str;//图片上传的拼接
    NSMutableArray *imageDataArr;
    
    NSMutableArray *inventoryArr;//库存的数组
    
    NSArray *wenBenArr;//文本的数组
    
}

@end
/*
 不调用复用机制
 */
@implementation BGFuJiaController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"附加信息";
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(next)];
    self.navigationItem.rightBarButtonItem = right;
    back = [[UIBarButtonItem alloc] init];
    back.title = @"上一步";

    self.navigationItem.backBarButtonItem = back;

    [self initDat];
    
    NSLog(@"啊啊啊啊啊啊%@",self.fabuName);
    NSLog(@"%@",self.typeId);
    NSLog(@"goods_id%@",self.goods_id);
    NSLog(@"self.status === %@",self.status);
    
    [self loadInter1];
    
    [self createUI];
    
}

- (void)initDat {
    
    str = [NSMutableString stringWithString:@"0"];
    
    textData = [NSMutableArray array];
    
    oneArr = [NSMutableArray array];
    twoArr = [NSMutableArray array];
    threeArr = [NSMutableArray array];
    fourArr = [NSMutableArray array];
    fiveArr = [NSMutableArray array];
    
    oneModelArr = [NSMutableArray array];
    twoModelArr = [NSMutableArray array];
    threeModelArr = [NSMutableArray array];
    fourModelArr = [NSMutableArray array];
    fiveModelArr = [NSMutableArray array];
    
    imageDataArr = [NSMutableArray array];
    
    inventoryArr = [NSMutableArray array];
    
    wenBenArr = [NSArray array];

}

/**
 change version
 */
- (void)loadInter1 {
    
    [MBProgressHUD showMessage:@"加载中..."];
     
        [BGDateResult readAddGoodsStepModifyTwoWith:self.goods_id success:^(NSObject *result) {
            
            [MBProgressHUD hideHUD];
            
            BGReadStepTwoModel *a = [BGReadStepTwoModel objectWithKeyValues:result];
            
            NSAssert(1, @"a === %@",a.keyValues);
            
            res = [NSArray array];
            if ([a.status isEqualToString:@"1"]) {
                
                BGReadStepTwoModelRes *resModel = [BGReadStepTwoModelRes objectWithKeyValues:a.res];
                res = resModel.attr;
                str = resModel.profilePic;
                for (BGReadStepTwoModelResAttr *model in res) {
                    
                    NSLog(@"model.attr_type === %@",model.keyValues);
                    
                    if ([model.attr_type isEqualToString:@"1"]) {//文本的
                        
                        [fourArr addObject:model];
                        [fourModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else if ([model.attr_type isEqualToString:@"2"]) {//图片的
                        
                        [twoArr addObject:model];
                        [twoModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else if ([model.attr_type isEqualToString:@"3"]) {
                        
                        //库存的专属
                        if ([model.search_flag isEqualToString:@"number"]) {
                            
                            //库存数组存的大模型BGReadStepTwoModelResAttr
                            [inventoryArr addObject:model];
                            
                        } else {//单选的
                        
                            if ([self.fabuName isEqualToString:@"0"] || [self.fabuName isEqualToString:@"2"]) {
                        [threeArr addObject:model];
                        [threeModelArr addObject:model.attr_values];
                        
                                [_tableView reloadData];
                            }else {
                                [fiveArr addObject:model];
                                [fiveModelArr addObject:model.attr_values];
                                
                                [_tableView reloadData];
                            }
                            
                        }
                        
                    }else if ([model.attr_type isEqualToString:@"4"]) {//多选的
                        
                        [oneArr addObject:model];
                        [oneModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else {//下拉的(单选)
                        
                        [fiveArr addObject:model];
                        [fiveModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }
                    
                }
                //上传数据必须有的啊
                //库存的数据
                if (inventoryArr.count != 0) {
                    BGReadStepTwoModelResAttr *model = inventoryArr.firstObject;
                    for (BGReadStepTwoModelArrDetail *infoModel in model.attr_values) {
                        NSArray *arr = [infoModel.value componentsSeparatedByString:@"-"];
                        if ([self.inventory integerValue] >[arr.firstObject integerValue] && [self.inventory integerValue] <= [arr.lastObject integerValue]) {
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":infoModel.changePrice,@"isUse":@"true",@"isDefault":@"true"}];
                            [textData addObject:dic];
                        }
                    }
                }
                //单选的数据
                if (threeArr.count != 0) {
                    
                    for (BGReadStepTwoModelResAttr *model in threeArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            
                            for (BGReadStepTwoModelArrDetail *infoModel in model.default_value) {
                                
                                NSString *isUseStr;
                                NSString *isDefaultStr;
                                if ([infoModel.isDefault isEqualToString:@"1"]) {
                                    isDefaultStr = @"true";
                                }else {
                                    isDefaultStr = @"false";
                                }
                                if ([infoModel.isUse isEqualToString:@"1"]) {
                                    isUseStr = @"true";
                                }else {
                                    isUseStr = @"false";
                                }
                                
                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":infoModel.changePrice,@"isUse":isUseStr,@"isDefault":isDefaultStr}];
                                [textData addObject:dic];
                                
                            }
                            
                        }
                        
                    }
                    
                }
                
                //多选的数据
                if (oneArr.count != 0) {
                    
                    for (BGReadStepTwoModelResAttr *model in oneArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            
                            for (BGReadStepTwoModelArrDetail *infoModel in model.default_value) {
                                NSString *isUseStr;
                                NSString *isDefaultStr;
                                if ([infoModel.isDefault isEqualToString:@"1"]) {
                                    isDefaultStr = @"true";
                                }else {
                                    isDefaultStr = @"false";
                                }
                                if ([infoModel.isUse isEqualToString:@"1"]) {
                                    isUseStr = @"true";
                                }else {
                                    isUseStr = @"false";
                                }
                                
                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
                                [textData addObject:dic];
                                
                            }
                            
                        }
                        
                    }
                    
                }
                
                //文本的数据
                if (fourArr.count != 0) {
                    
                    for (BGReadStepTwoModelResAttr *model in fourArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            BGReadStepTwoModelArrDetail *infoModel = model.default_value.firstObject;
                            NSString *isUseStr;
                            NSString *isDefaultStr;
                            if ([infoModel.isDefault isEqualToString:@"1"]) {
                                isDefaultStr = @"true";
                            }else {
                                isDefaultStr = @"false";
                            }
                            if ([infoModel.isUse isEqualToString:@"1"]) {
                                isUseStr = @"true";
                            }else {
                                isUseStr = @"false";
                            }
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":@"true"}];
                            [textData addObject:dic];

                        } else {
                        if (model.attr_values.count != 0) {
                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
                            NSString *isUseStr;
                            NSString *isDefaultStr;
                            if ([infoModel.isDefault isEqualToString:@"1"]) {
                                isDefaultStr = @"true";
                            }else {
                                isDefaultStr = @"false";
                            }
                            if ([infoModel.isUse isEqualToString:@"1"]) {
                                isUseStr = @"true";
                            }else {
                                isUseStr = @"false";
                            }
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":@"true"}];
                            [textData addObject:dic];
                        }
                        else {
                            
                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
                            NSString *isUseStr;
                            NSString *isDefaultStr;
                            if ([infoModel.isDefault isEqualToString:@"1"]) {
                                isDefaultStr = @"true";
                            }else {
                                isDefaultStr = @"false";
                            }
                            if ([infoModel.isUse isEqualToString:@"1"]) {
                                isUseStr = @"true";
                            }else {
                                isUseStr = @"false";
                            }
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":@"",@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
    
                            [textData addObject:dic];
                        }
                        
                    }
                    
                }
                }
                //下拉的数据
                if (fiveArr.count != 0) {
                    
                    for (BGReadStepTwoModelResAttr *model in fiveArr) {
                        
                        if (model.default_value.count != 0) {
                            
                            for (BGReadStepTwoModelArrDetail *infoModel in model.default_value) {
                                
                                NSString *isUseStr;
                                NSString *isDefaultStr;
                                if ([infoModel.isDefault isEqualToString:@"1"]) {
                                    isDefaultStr = @"true";
                                }else {
                                    isDefaultStr = @"false";
                                }
                                if ([infoModel.isUse isEqualToString:@"1"]) {
                                    isUseStr = @"true";
                                }else {
                                    isUseStr = @"false";
                                }
                                
                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
                                [textData addObject:dic];
                            }
  
                        }
//                        else {
//                            
//                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
//                            
//                            NSString *isUseStr;
//                            NSString *isDefaultStr;
//                            if ([infoModel.isDefault isEqualToString:@"1"]) {
//                                isDefaultStr = @"true";
//                            }else {
//                                isDefaultStr = @"false";
//                            }
//                            if ([infoModel.isUse isEqualToString:@"1"]) {
//                                isUseStr = @"true";
//                            }else {
//                                isUseStr = @"false";
//                            }
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
//                            [textData addObject:dic];
//                        }
                        
                    }
                    
                }
                
            }else {
                
                [self showMessage:a.msg];
                
            }
            
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUD];
            [MBProgressHUD showError:@"请求失败!"];
        }];
    NSLog(@"textData === %@",textData);
    }
//    else {
//        
//        [BGDateResult readAddGoodsStepModifyTwoWith:self.goods_id success:^(NSObject *result) {
//            
//            [MBProgressHUD hideHUD];
//            
//            BGReadStepTwoModel *a = [BGReadStepTwoModel objectWithKeyValues:result];
//            
//            NSAssert(1, @"a === %@",a.keyValues);
//            
//            res = [NSArray array];
//            if ([a.status isEqualToString:@"1"]) {
//                
//                BGReadStepTwoModelRes *resModel = [BGReadStepTwoModelRes objectWithKeyValues:a.res];
//                res = resModel.attr;
//                str = resModel.profilePic;
//                for (BGReadStepTwoModelResAttr *model in res) {
//                    
//                    NSLog(@"model.attr_type === %@",model.keyValues);
//                    
//                    if ([model.attr_type isEqualToString:@"1"]) {
//                        
//                        [fourArr addObject:model];
//                        [fourModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"2"]) {
//                        
//                        [twoArr addObject:model];
//                        [twoModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"3"]) {
//                        
//                        [fiveArr addObject:model];
//                        [fiveModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"4"]) {
//                        
//                        [oneArr addObject:model];
//                        [oneModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else {
//                        
//                        [fiveArr addObject:model];
//                        [fiveModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }
//                    
//                }
//                
//                //上传数据必须有的啊
//                if (oneArr.count != 0) {
//                    
//                    for (BGReadStepTwoModelResAttr *model in oneArr) {
//                        
//                        //防止default_value 没有值
//                        if (model.default_value.count != 0) {
//                            
//                            for (BGReadStepTwoModelArrDetail *infoModel in model.default_value) {
//                                NSString *isUseStr;
//                                NSString *isDefaultStr;
//                                if ([infoModel.isDefault isEqualToString:@"1"]) {
//                                    isDefaultStr = @"true";
//                                }else {
//                                    isDefaultStr = @"false";
//                                }
//                                if ([infoModel.isUse isEqualToString:@"1"]) {
//                                    isUseStr = @"true";
//                                }else {
//                                    isUseStr = @"false";
//                                }
//                                
//                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
//                                [textData addObject:dic];
//                                
//                            }
//                            
//                        }
//                        
//                    }
//                    
//                }
//                
//                if (fourArr.count != 0) {
//                    
//                    for (BGReadStepTwoModelResAttr *model in fourArr) {
//                        
//                        //防止default_value 没有值
//                        if (model.attr_values.count != 0) {
//                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
//                            NSString *isUseStr;
//                            NSString *isDefaultStr;
//                            if ([infoModel.isDefault isEqualToString:@"1"]) {
//                                isDefaultStr = @"true";
//                            }else {
//                                isDefaultStr = @"false";
//                            }
//                            if ([infoModel.isUse isEqualToString:@"1"]) {
//                                isUseStr = @"true";
//                            }else {
//                                isUseStr = @"false";
//                            }
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
//                            [textData addObject:dic];
//                        }else {
//                            
//                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
//                            NSString *isUseStr;
//                            NSString *isDefaultStr;
//                            if ([infoModel.isDefault isEqualToString:@"1"]) {
//                                isDefaultStr = @"true";
//                            }else {
//                                isDefaultStr = @"false";
//                            }
//                            if ([infoModel.isUse isEqualToString:@"1"]) {
//                                isUseStr = @"true";
//                            }else {
//                                isUseStr = @"false";
//                            }
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":@"",@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
//                            
//                            [textData addObject:dic];
//                        }
//                        
//                    }
//                    
//                }
//                
//                if (fiveArr.count != 0) {
//                    
//                    for (BGReadStepTwoModelResAttr *model in fiveArr) {
//                        
//                        if (model.default_value.count != 0) {
//                           for (BGReadStepTwoModelArrDetail *infoModel in model.default_value) {
//                            NSString *isUseStr;
//                            NSString *isDefaultStr;
//                            if ([infoModel.isDefault isEqualToString:@"1"]) {
//                                isDefaultStr = @"true";
//                            }else {
//                                isDefaultStr = @"false";
//                            }
//                            if ([infoModel.isUse isEqualToString:@"1"]) {
//                                isUseStr = @"true";
//                            }else {
//                                isUseStr = @"false";
//                            }
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
//                            [textData addObject:dic];
//                           }
//                        }
////                        else {
////                            
////                            BGReadStepTwoModelArrDetail *infoModel = model.attr_values.firstObject;
////                            
////                            NSString *isUseStr;
////                            NSString *isDefaultStr;
////                            if ([infoModel.isDefault isEqualToString:@"1"]) {
////                                isDefaultStr = @"true";
////                            }else {
////                                isDefaultStr = @"false";
////                            }
////                            if ([infoModel.isUse isEqualToString:@"1"]) {
////                                isUseStr = @"true";
////                            }else {
////                                isUseStr = @"false";
////                            }
////                            
////                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.ID,@"value":infoModel.value,@"changePrice":@"0.00",@"isUse":isUseStr,@"isDefault":isDefaultStr}];
////                            [textData addObject:dic];
////                        }
//                        
//                    }
//                    
//                }
//                
//            }else {
//                
//                [self showMessage:a.msg];
//                
//            }
//            
//        } failure:^(NSError *error) {
//            [MBProgressHUD hideHUD];
//            [MBProgressHUD showError:@"请求失败!"];
//        }];
//        
//    }
//

- (void)loadInter {
    
    [MBProgressHUD showMessage:@"加载中..."];
    
    if ([self.fabuName isEqualToString:@"0"] || [self.fabuName isEqualToString:@"2"]) {
        
        [BGDateResult readAddGoodsStepTwoWith:self.goods_id success:^(NSObject *result) {
            
            [MBProgressHUD hideHUD];
            
            BGReadAddGoodsStepTWoModel *a = (BGReadAddGoodsStepTWoModel *)result;
            
            res = [NSArray array];
            
            if ([a.status isEqualToString:@"1"]) {
                
                BGReadAddGoodsStepTWoModelRes *modelress = [BGReadAddGoodsStepTWoModelRes objectWithKeyValues:a.res];
                
                res = modelress.attr;
                str = modelress.profilePic;
                
                for (BGReadAddGoodsStepTWoModelResAttr *model in res) {
                    
                    NSLog(@"model.attr_type === %@",model.keyValues);
                    
                    if ([model.attr_type isEqualToString:@"1"]) {
                        
                        [fourArr addObject:model];
                        [fourModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else if ([model.attr_type isEqualToString:@"2"]) {
                        
                        [twoArr addObject:model];
                        [twoModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else if ([model.attr_type isEqualToString:@"3"]) {
                        
                        [threeArr addObject:model];
                        [threeModelArr addObject:model.attr_values];
                        
                        [_tableView reloadData];
                        
                    }else if ([model.attr_type isEqualToString:@"4"]) {
                        
                        [oneArr addObject:model];
                        [oneModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }else {
                        
                        [fiveArr addObject:model];
                        [fiveModelArr addObject:model.attr_values];
                        [_tableView reloadData];
                        
                    }
                    
                }
//                NSLog(@"threeModel === %@",threeModelArr);
                //上传数据必须有的啊
                if (threeArr.count != 0) {
                    
                    for (BGReadAddGoodsStepTWoModelResAttr *model in threeArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            
                            for (BGReadAddGoodsStepTWoModelResAttrInfo *infoModel in model.default_value) {
                                
                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":infoModel.changePrice}];
                                [textData addObject:dic];
                                
                            }
                            
                        }
                        
                    }
                    
                }

                
                if (oneArr.count != 0) {
                    
                    for (BGReadAddGoodsStepTWoModelResAttr *model in oneArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            
                            for (BGReadAddGoodsStepTWoModelResAttrInfo *infoModel in model.default_value) {
                                
                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
                                [textData addObject:dic];
                                
                            }
                            
                        }
                        
                    }
                    
                }
                
                if (fourArr.count != 0) {
                    
                    for (BGReadAddGoodsStepTWoModelResAttr *model in fourArr) {
                        
                        //防止default_value 没有值
                        if (model.default_value.count != 0) {
                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.default_value.firstObject;
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
                            [textData addObject:dic];
                        }else {
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":@"",@"changePrice":@"0.00"}];
                            [textData addObject:dic];
                        }
                        
                    }
                    
                }
                
                if (fiveArr.count != 0) {
                    
                    for (BGReadAddGoodsStepTWoModelResAttr *model in fiveArr) {
                        
                        if (model.default_value.count != 0) {
                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.default_value.firstObject;
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
                            [textData addObject:dic];
                        }else {
                            
                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.attr_values.firstObject;
                            
                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
                            [textData addObject:dic];
                        }
                        
                    }
                    
                }
                
            }else {
                
                NSLog(@"%@",a.msg);
                [self showMessage:a.msg];
                
            }
            
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUD];
            [MBProgressHUD showError:@"请求失败!"];
        }];
       
        
    }
//    else {
//        
//        [BGDateResult readAddGoodsStepTwoWith:self.goods_id success:^(NSObject *result) {
//            
//            [MBProgressHUD hideHUD];
//            
//            BGReadAddGoodsStepTWoModel *a = (BGReadAddGoodsStepTWoModel *)result;
//            
//            res = [NSArray array];
//            
//            if ([a.status isEqualToString:@"1"]) {
//                
//                 BGReadAddGoodsStepTWoModelRes *modelress = [BGReadAddGoodsStepTWoModelRes objectWithKeyValues:a.res];;
//                
//                res = modelress.attr;
//                str = modelress.profilePic;
//                
//                for (BGReadAddGoodsStepTWoModelResAttr *model in res) {
//                    
//                    if ([model.attr_type isEqualToString:@"1"]) {
//                        
//                        [fourArr addObject:model];
//                        [fourModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"2"]) {
//                        
//                        [twoArr addObject:model];
//                        [twoModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"3"]) {
//                        
//                        [fiveArr addObject:model];
//                        [fiveModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else if ([model.attr_type isEqualToString:@"4"]) {
//                        
//                        [oneArr addObject:model];
//                        [oneModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }else {
//                        
//                        [fiveArr addObject:model];
//                        [fiveModelArr addObject:model.attr_values];
//                        [_tableView reloadData];
//                        
//                    }
//                    
//                }
//                
//                //上传数据必须有的啊
//                if (oneArr.count != 0) {
//                    
//                    for (BGReadAddGoodsStepTWoModelResAttr *model in oneArr) {
//                        
//                        //防止default_value 没有值
//                        if (model.default_value.count != 0) {
//                            
//                            for (BGReadAddGoodsStepTWoModelResAttrInfo *infoModel in model.default_value) {
//                                
//                                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
//                                [textData addObject:dic];
//                                
//                            }
//                            
//                        }
//                        
//                    }
//                    
//                }
//                
//                if (fourArr.count != 0) {
//                    
//                    for (BGReadAddGoodsStepTWoModelResAttr *model in fourArr) {
//                        
//                        if (model.default_value.count != 0) {
//                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.default_value.firstObject;
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
//                            [textData addObject:dic];
//                        }else {
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":@"",@"changePrice":@"0.00"}];
//                            [textData addObject:dic];
//                        }
//                        
//                    }
//                    
//                }
//                
//                if (fiveArr.count != 0) {
//                    
//                    for (BGReadAddGoodsStepTWoModelResAttr *model in fiveArr) {
//                        
//                        if (model.default_value.count != 0) {
//                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.default_value.firstObject;
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
//                            [textData addObject:dic];
//                        }else {
//                            
//                            BGReadAddGoodsStepTWoModelResAttrInfo *infoModel = model.attr_values.firstObject;
//                            
//                            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":model.idStr,@"value":infoModel.value,@"changePrice":@"0.00"}];
//                            [textData addObject:dic];
//                        }
//                        
//                    }
//                    
//                }
//                
//            }else {
//                
//                NSLog(@"%@",a.msg);
//                [self showMessage:a.msg];
//                
//            }
//
//            
//        } failure:^(NSError *error) {
//            [MBProgressHUD hideHUD];
//            [MBProgressHUD showError:@"请求失败!"];
//        }];
//        
//    }
//    
}
- (void)createUI {
    
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView .delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.view addSubview:_tableView];
    
}
- (void)showMessage:(NSString *)message {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}
#pragma mark - dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    if ([self.fabuName isEqualToString:@"1"]) {
        
        return 6;
        
    }else {
      
        return 6;
        
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([self.fabuName isEqualToString:@"1"]) {
        
        if (section == 0) {
            
            return inventoryArr.count; //库存的
            
        }else if (section == 1) {
            
            return fourArr.count;//文本的
            
        }else if (section == 2){
            
            return fiveArr.count;//下拉的
            
        }else if (section == 3){
            
            return oneArr.count;//多选的
            
        }else if (section == 4){
            
            return threeArr.count;//单选的
            
        }else {
            
            return 1;//图片的
            
        }

        
    }else {
    
        if (section == 0) {
            
            return inventoryArr.count; //库存的
            
        }else if (section == 1) {
            
            return fourArr.count;//文本的
            
        }else if (section == 2){
            
            return fiveArr.count;//下拉的
            
        }else if (section == 3){
            
            return oneArr.count;//多选的
            
        }else if (section == 4){
            
            return threeArr.count;//单选的
            
        }else {
            
            return 1;//图片的
            
        }
//         return threeArr.count;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        if (inventoryArr.count == 0) {
            return 0.1;
        } else {
            return 30;
        }
    }else if (section == 1) {
        if (fourArr.count == 0) {
            return 0.1;
        } else {
            return 30;
        }
        
    }else if (section == 2) {
        if (fiveArr.count == 0) {
            return 0.1;
        } else {
            return 30;
        }
        
    }else if (section == 3) {
        if (oneArr.count == 0) {
            return 0.1;
        } else {
            return 30;
        }

    }else if (section == 4) {
        if (threeArr.count == 0) {
            return 0.1;
        } else {
            return 30;
        }
    }
    
    else {
        return 30;
    }

    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
        return 0.1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if (indexPath.section == 0) {
            return 43;
        }else if (indexPath.section == 1){
            
            return 43;
            
        }else if (indexPath.section == 2){
            
            BGReadAddGoodsStepTWoModelResAttr *model = fiveArr[indexPath.row];
            return model.attr_values.count * 30 + 55;
            
        }else if (indexPath.section == 3){
           
           BGReadAddGoodsStepTWoModelResAttr *model = oneArr[indexPath.row];
            return model.attr_values.count * 30 + 55;

        }else if (indexPath.section == 4){
            
            BGReadAddGoodsStepTWoModelResAttr *model = threeArr[indexPath.row];
            return model.attr_values.count * 30 + 55;
            
        }else {
            
            return 340;
            
        }
//    BGReadAddGoodsStepTWoModelResAttr *model = threeArr[indexPath.row];
//                return model.attr_values.count * 30 + 55;;
    
}
#pragma mark - delegate
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    
//        if (indexPath.section == 0) {
//            
//            BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
//            if (fourArr.count != 0) {
//                
//                model = fourArr[indexPath.row];
//                
//            }
//            //填写的
//            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//            BGFourCell *cel = [tableView dequeueReusableCellWithIdentifier:@"celId4"];
//
//            if (cel == nil) {
//                cel = [[BGFourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"celId4" default_value:model.default_value];
//            }
//            
//            
//            
//            if (fourArr.count != 0) {
//                
//                model = fourArr[indexPath.row];
//                cel.titleText = model.name;
//                cel.attr_id = model.ID;
//                
//            }
//        
//            if (fourModelArr.count != 0) {
//                cel.arr1 = fourModelArr[indexPath.row];
//            }
//            
//            //根据状态改变cel交互能力
//            if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"]) {
//                cel.userInteractionEnabled = NO;
//            }else if ([self.status isEqualToString:@"-1"] || [self.status isEqualToString:@"2"]){
//                cel.userInteractionEnabled = YES;
//            }
//        
//            cel.delegate = self;
//            cel.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cel;
//        }else if (indexPath.section == 1) {
//            
//             NSString *FiveStr = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
//             BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
//            if (fiveArr.count != 0) {
//                
//                model = fiveArr[indexPath.row];
//                
//            }
//            //pickerView
//            BGFiveCell *cel = [tableView dequeueReusableCellWithIdentifier:FiveStr];
//            if (cel == nil) {
//                cel = [[BGFiveCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FiveStr dataArr:fiveModelArr[indexPath.row] default_value:model.default_value];
//            }
//            
//            if (fiveArr.count != 0) {
//                
//                model = fiveArr[indexPath.row];
//                cel.titleText = model.name;
//                cel.attr_id = model.ID;
//                
//            }
//            if (fiveModelArr.count != 0) {
//                cel.arr = fiveModelArr[indexPath.row];
//            }
//            
//            //根据状态改变cel交互能力
//            if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"]) {
//                cel.userInteractionEnabled = NO;
//            }else if ([self.status isEqualToString:@"-1"] || [self.status isEqualToString:@"2"]){
//                cel.userInteractionEnabled = YES;
//            }
//            
//            cel.delegate = self;
//            cel.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cel;
//        }else if (indexPath.section == 2) {
//            NSString *oneStr = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
//             BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
//            if (oneArr.count != 0) {
//                
//                model = oneArr[indexPath.row];
//                
//            }
//            //按钮多选择
//            BGOneCell *cel = [tableView dequeueReusableCellWithIdentifier:oneStr];
//            if (cel == nil) {
//                cel = [[BGOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:oneStr dataArr:oneModelArr[indexPath.row] default_value:model.default_value index:indexPath];
//            }
//            
//            if (oneArr.count != 0) {
//                
//                model = oneArr[indexPath.row];
//                cel.titleText = model.name;
//                cel.attr_id = model.ID;
//                [tableView setNeedsLayout];
//                
//            }
//            if (oneModelArr.count != 0) {
////                cel.arr = oneModelArr[indexPath.row];
//            }
//            
//            //根据状态改变cel交互能力
//            if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"]) {
//                cel.userInteractionEnabled = NO;
//            }else if ([self.status isEqualToString:@"-1"] || [self.status isEqualToString:@"2"]){
//                cel.userInteractionEnabled = YES;
//            }
//            
//            cel.delegate = self;
//            cel.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cel;
//        }else if (indexPath.section == 3) {
//
//            NSString *threeStr = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
//            
//            BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
//            if (threeArr.count != 0) {
//                
//                model = threeArr[indexPath.row];
//                
//            }
//          // 按钮可填写
//             BGThreeCell *cel = [tableView dequeueReusableCellWithIdentifier:threeStr];
//            if (cel == nil) {
//                cel = [[BGThreeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:threeStr dataArr:threeModelArr[indexPath.row] default_value:model.default_value];
//                
////                BGFuJiaThreeModel *FuJiaThreeModel = [[BGFuJiaThreeModel alloc] init];
////                FuJiaThreeModel.marr = threeModelArr[indexPath.row];
////                FuJiaThreeModel.default_valueArr = model.default_value;
//                
////                cel.modelThree = FuJiaThreeModel;
//                
//                NSLog(@"indexPath.row === %ld",(long)indexPath.row);
//                NSLog(@"threeModelArr[indexPath.row] === %@",threeModelArr[indexPath.row]);
//            }
//           
//            cel.delegate = self;
//            
//            
//            if (threeArr.count != 0) {
//                
//                model = threeArr[indexPath.row];
//                cel.titleText = model.name;
//                cel.attr_id = model.ID;
//                
//            }
//
//            //根据状态改变cel交互能力
//            if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"]) {
//                cel.userInteractionEnabled = NO;
//            }else if ([self.status isEqualToString:@"-1"] || [self.status isEqualToString:@"2"]){
//                cel.userInteractionEnabled = YES;
//            }
//            
//            cel.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cel;
//        }else {
//            
//            //选图片
//            BGTwoCell *cel = [tableView dequeueReusableCellWithIdentifier:@"celId2"];
//            if (cel == nil) {
//                cel = [[BGTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"celId2"];
//            }
//            
//            //根据状态改变cel交互能力
//            if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"]) {
//                cel.userInteractionEnabled = NO;
//            }else if ([self.status isEqualToString:@"-1"] || [self.status isEqualToString:@"2"]){
//                cel.userInteractionEnabled = YES;
//            }
//            
//            cel.delegate = self;
//            cel.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cel;
//        
//        }
////    }
//    
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        //库存的
        BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
        if (inventoryArr.count != 0) {
            model = inventoryArr[indexPath.row];
        }
        BGInventoryCell *cel = [tableView dequeueReusableCellWithIdentifier:@"celId0"];
        if (cel == nil) {
            cel = [[BGInventoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"celId0" inventory:self.inventory];
            cel.titleText = model.name;
            cel.attr_id = model.ID;
        }
        
        return cel;
        
    }else if (indexPath.section == 1) {
        
        //文本的
        NSString *wenbenId = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
        
        BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
        if (fourArr.count != 0) {
            model = fourArr[indexPath.row];
        }
        wenBenArr = model.default_value;
        if (model.default_value.count == 0) {
            wenBenArr = model.attr_values;
        }
        BGWenBenCell *cel = [tableView dequeueReusableCellWithIdentifier:wenbenId];
        if (cel == nil) {
            cel = [[BGWenBenCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:wenbenId default_value:wenBenArr fabuName:self.fabuName];
            cel.titleText = model.name;
            cel.attr_id = model.ID;
            cel.delegate = self;
        }
        //根据状态改变cel交互能力
        if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
            cel.userInteractionEnabled = NO;
        }else if ([self.status isEqualToString:@"-1"]){
            cel.userInteractionEnabled = YES;
        }
        
        cel.selectionStyle = UITableViewCellSelectionStyleNone;
        return cel;
        
    }else if (indexPath.section == 2) {
        
        //下拉的
        NSString *xialaId = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
        
        BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
        if (fiveArr.count != 0) {
            model = fiveArr[indexPath.row];
        }
        BGDanXuanCell *cel = [tableView dequeueReusableCellWithIdentifier:xialaId];
        if (cel == nil) {
            cel = [[BGDanXuanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:xialaId attr_values:model.attr_values default_value:model.default_value fabuName:self.fabuName];
            cel.titleText = model.name;
            cel.attr_id = model.ID;
            cel.delegate = self;
        }
        //根据状态改变cel交互能力
        if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
            cel.userInteractionEnabled = NO;
        }else if ([self.status isEqualToString:@"-1"]){
            cel.userInteractionEnabled = YES;
        }
        
        cel.selectionStyle = UITableViewCellSelectionStyleNone;
        return cel;
        
    }else if (indexPath.section == 3) {
        
        //多选的
        NSString *duoxuanId = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
        
        BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
        if (oneArr.count != 0) {
            model = oneArr[indexPath.row];
        }
        BGDuoXuanCell *cel = [tableView dequeueReusableCellWithIdentifier:duoxuanId];
        if (cel == nil) {
            cel = [[BGDuoXuanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:duoxuanId attr_values:model.attr_values default_value:model.default_value fabuName:self.fabuName];
            cel.titleText = model.name;
            cel.attr_id = model.ID;
            cel.delegate = self;
        }
        //根据状态改变cel交互能力
        if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
            cel.userInteractionEnabled = NO;
        }else if ([self.status isEqualToString:@"-1"]){
            cel.userInteractionEnabled = YES;
        }
        
        cel.selectionStyle = UITableViewCellSelectionStyleNone;
        return cel;
    }else if (indexPath.section == 4) {
        
        //单选的
        NSString *danXuanId = [NSString stringWithFormat:@"CELID%ld%ld",(long)indexPath.section,(long)indexPath.row];
        
        BGReadStepTwoModelResAttr *model = [[BGReadStepTwoModelResAttr alloc] init];
        if (threeArr.count != 0) {
            model = threeArr[indexPath.row];
        }
        
        BGDanXuanCell *cel = [tableView dequeueReusableCellWithIdentifier:danXuanId];
        
        if (cel == nil) {
            cel = [[BGDanXuanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:danXuanId attr_values:model.attr_values default_value:model.default_value fabuName:self.fabuName];
            cel.delegate = self;
            cel.titleText = model.name;
            cel.attr_id = model.ID;
        }
        
        //根据状态改变cel交互能力
        if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
            cel.userInteractionEnabled = NO;
        }else if ([self.status isEqualToString:@"-1"]){
            cel.userInteractionEnabled = YES;
        }
        
        cel.selectionStyle = UITableViewCellSelectionStyleNone;
        return cel;

    }else {
        
        //图片的
        BGTwoCell *cel = [tableView dequeueReusableCellWithIdentifier:@"celId2"];
                    if (cel == nil) {
                        cel = [[BGTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"celId2"];
                    }
        
                    //根据状态改变cel交互能力
                    if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
                        cel.userInteractionEnabled = NO;
                    }else if ([self.status isEqualToString:@"-1"]){
                        cel.userInteractionEnabled = YES;
                    }
        
                    cel.delegate = self;
                    cel.selectionStyle = UITableViewCellSelectionStyleNone;
                    return cel;
        
    }
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        if (inventoryArr.count == 0) {
            return nil;
        } else {
        return @"库存";
        }
    }else if (section == 1) {
        if (fourArr.count == 0) {
            return nil;
        } else {
            return @"文本填写";
        }
        
    }else if (section == 2) {
        if (fiveArr.count == 0) {
            return nil;
        } else {
            return @"下拉模式";
        }
       
    }else if (section == 3) {
        if (oneArr.count == 0) {
            return nil;
        } else {
            return @"多选模式";
        }
        
    }
    else if (section == 4) {
        if (threeArr.count == 0) {
            return nil;
        } else {
            return @"单选模式";
        }
    }else {
        return @"仓单图片";
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}
+ (void)hideEmptySeparators:(UITableView *)tableView
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    [tableView setTableFooterView:v];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
}
- (void)next {
    
    _tableView.contentOffset = CGPointMake(0, 3);
    
    if ([self.status isEqualToString:@"0"] || [self.status isEqualToString:@"1"] || [self.status isEqualToString:@"2"]) {
        
        BGHuoPinZhengShuController *a = [[BGHuoPinZhengShuController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        
        NSLog(@"self.goodsId === %@",self.goods_id);
        
        a.objectId = self.goods_id;
        a.status = self.status;
        [self.navigationController pushViewController:a animated:YES];
        
    } else {
        
//        if (imageDataArr.count == 0) {
//            str = [NSMutableString stringWithString:@""];
//        }
        
         NSLog(@"str === %@",str);
        NSLog(@"%@",textData);
    [BGDateResult addGoodsStepTwoWithParamDic:@{@"objectId":self.goods_id,@"profilePic":str,@"attrValue":textData} success:^(NSObject *result) {
        
        BGAddGoodsStepTwoModel *model = (BGAddGoodsStepTwoModel *)result;
        
        if ([model.status isEqualToString:@"1"]) {
            BGHuoPinZhengShuController *a = [[BGHuoPinZhengShuController alloc] init];
            self.hidesBottomBarWhenPushed = YES;
            
            NSLog(@"self.goodsId === %@",self.goods_id);
            
            a.status = self.status;
            a.objectId = self.goods_id;
            [self.navigationController pushViewController:a animated:YES];
            [self showMessage:model.msg];
        } else {
            [self showMessage:model.msg];
        }
        
    } failure:^(NSError *error) {
        
    }];
    
    }
}

#pragma mark - cellDelegate -
- (void)valueChange:(UIButton *)btn index:(NSString *)indexId{
    NSDictionary *dic = @{@"attrId":indexId,@"value":btn.titleLabel.text,@"changePrice":@"0.00"};
    
//    for (NSMutableDictionary *dicM in textData) {
//        if ([dicM[@"value"] isEqualToString:btn.titleLabel.text]) {
//            if (btn.selected == NO) {
//                [textData removeObject:dicM];
//            }
//            else {
//                [textData addObject:dicM];
//            }
//        }
//    }
    
    if (btn.selected == YES) {
        [textData addObject:dic];
//        NSLog(@"%@",textData);
        NSLog(@"%@",indexId);
    }else {
        [textData removeObject:dic];
    }
    NSLog(@"%@",textData);
}
- (void)valueChangeThree:(UIButton *)btn lab:(UILabel *)lab index:(NSString *)indexId {
    
    NSDictionary *dic = @{@"attrId":indexId,@"value":lab.text,@"changePrice":@""};

    if (btn.selected == NO) {
        [textData removeObject:dic];
//        for (NSDictionary *dic1 in textData) {
//            if ([dic1[@"value"] isEqualToString:dic[@"value"]]) {
//
//            }
//        }
        
    }else {
        
    }

    
}
- (void)imagesChange:(NSMutableArray *)dataArr index:(NSString *)idIndex {
    
    imageDataArr = dataArr;
    
    for (int i = 0; i < dataArr.count; i++) {
        
        if (i == 0) {
            str = [NSMutableString stringWithFormat:@"%@",dataArr[i]];
        }else {
            str = [NSMutableString stringWithFormat:@"%@,%@",str,dataArr[i]];
        }
        
    }
    
    if (dataArr.count == 0) {
        str = [NSMutableString stringWithString:@"0"];
    }

    
}
- (void)labValueChange:(NSString *)value filedValueChange:(UITextField *)filedText index:(NSString *)indexId {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":indexId,@"value":value,@"changePrice":filedText.text}];
    
    for (NSDictionary *dic1 in textData) {
        
        if ([dic[@"value"] isEqualToString:dic1[@"value"]]) {
            
//            if ([filedText.text isEqualToString:@""]) {
//                
//                [textData removeObject:dic1];
//                
//            }else {
            
            [dic1 setValue:filedText.text forKey:@"changePrice"];
            
//            }
            
            if (filedText.text == nil) {
                [textData removeObject:dic1];
            }
            
            return;
        }
//        else {
//            
        
//
//        }
        
    }
    
    if (![filedText.text isEqualToString:@""]) {
    
     [textData addObject:dic];
        
    }
    NSLog(@"%@",textData);
    
}
- (void)filedValueChange:(UITextField *)filed index:(NSString *)indexId {
//     NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":indexId,@"value":filed.text,@"changePrice":@"0.00"}];
    
    for (NSMutableDictionary *dicM in textData) {
        if ([dicM[@"attrId"] isEqualToString:indexId]) {
            [dicM setValue:filed.text forKey:@"value"];
        }
    }
    
//    if (![filed.text  isEqual: @""]) {
//        [textData addObject:dic];
//    }
   
    NSLog(@"%@",textData);
}
- (void)pickerValueChange:(NSString *)value index:(NSString *)indexId {
    
    for (NSMutableDictionary *dicM in textData) {
        if ([dicM[@"attrId"] isEqualToString:indexId]) {
            [dicM setValue:value forKey:@"value"];
        }
    }

    NSLog(@"%@",textData);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillDisappear:(BOOL)animated {
    [BGFaBuViewController share].type = @"fujia";
    for (UIView *v in [UIApplication sharedApplication].keyWindow.subviews) {
        if ([v isKindOfClass:[UIPickerView class]] || [v isKindOfClass:[UIScrollView class]]) {
            [v setHidden:YES];
        }
    }
}
- (void)attr_id:(NSString *)attr_id isDefault:(NSString *)isDefault isUse:(NSString *)isUse changePrice:(NSString *)changePrice value:(NSString *)value {
    
    BOOL a = NO;
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":attr_id,@"value":value,@"changePrice":changePrice,@"isUse":isUse,@"isDefault":isDefault}];
    
    //删除之前的数据
    if ([isUse isEqualToString:@"false"]) {
        for (NSMutableDictionary *dicM_false in textData) {
            if ([[dicM_false objectForKey:@"attrId"] isEqualToString:attr_id] && [[dicM_false objectForKey:@"value"] isEqualToString:value]) {
                [textData removeObject:dicM_false];
                return;
            }
        }
    }
    
    //修改了数据
    if ([isUse isEqualToString:@"true"]) {
        for (NSMutableDictionary *dic_true in textData) {
            if ([[dic_true objectForKey:@"attrId"] isEqualToString:attr_id] && [[dic_true objectForKey:@"value"] isEqualToString:value]) {
                [dic_true setObject:changePrice forKey:@"changePrice"];
                [dic_true setObject:isUse forKey:@"isUse"];
                [dic_true setObject:isDefault forKey:@"isDefault"];
                a = YES;
                break;
                
            }
        }
    }
    
   //添加新数据
    if (a == NO) {
        [textData addObject:dic];
    }
    
}
- (void)wenBenattr_id:(NSString *)attr_id isDefault:(NSString *)isDefault isUse:(NSString *)isUse changePrice:(NSString *)changePrice value:(NSString *)value {
    BOOL a = NO;
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"attrId":attr_id,@"value":value,@"changePrice":@"0.00",@"isUse":isUse,@"isDefault":isDefault}];
    
    //删除之前的数据
    if ([isUse isEqualToString:@"false"]) {
        for (NSMutableDictionary *dicM_false in textData) {
            if ([[dicM_false objectForKey:@"attrId"] isEqualToString:attr_id] && [[dicM_false objectForKey:@"value"] isEqualToString:value]) {
                [textData removeObject:dicM_false];
                return;
            }
        }
    }
    
    //修改了数据
    if ([isUse isEqualToString:@"true"]) {
        for (NSMutableDictionary *dic_true in textData) {
            if ([[dic_true objectForKey:@"attrId"] isEqualToString:attr_id]) {
                [dic_true setObject:value forKey:@"value"];
                [dic_true setObject:isUse forKey:@"isUse"];
                [dic_true setObject:isDefault forKey:@"isDefault"];
                a = YES;
                break;
                
            }
        }
    }
    
    //添加新数据
    if (a == NO) {
        [textData addObject:dic];
    }

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
